import "./App.css";
import React, { forwardRef } from "react";
import hoistNonReactStatic from "hoist-non-react-statics";
function withHoc(WrapCp) {
  class Result extends React.Component {
    render() {
      const { forwardRef, ...rest } = this.props;
      return <WrapCp {...rest} ref={forwardRef} />;
    }
  }
  hoistNonReactStatic(Result, WrapCp);
  // hoc里面需要进行forwardRef转发
  return React.forwardRef((props, ref) => {
    return <Result forwardRef={ref} {...props} />;
  });
}
class App extends React.Component {
  static getName = () => {
    console.log("我是getName");
  };
  static getAge = () => {
    console.log("age: 18");
  };
  render() {
    return (
      <div className="App">
        <h1>Hello World</h1>
      </div>
    );
  }
}
const WrapCp = withHoc(App);

class TestRef extends React.Component {
  constructor() {
    super();
    this.ref = React.createRef();
  }
  componentDidMount() {
    console.log(this.ref);
  }
  render() {
    return <WrapCp ref={this.ref} />;
  }
}
export default TestRef;
